<? $f = new \Html\Form($role)?>
<div class="field">
  <?= $f->label('name') ?><br />
  <?= $f->text_field('name') ?>
  <?= $f->error_message_for('name') ?>
</div>
<div class="field">
  <?= $f->label('description') ?><br />
  <?= $f->textarea('description') ?>
  <?= $f->error_message_for('description') ?>
</div>
<div class="field">
  <?= $f->label('users') ?><br />
  <?= hidden_field_tag('role[user_ids][]', '') ?>
  <? foreach($users as $user) : ?>
  <div>
    <?= check_box_tag('role[user_ids][]', $user->id, in_array($user->id, User::collection_to_array($role->users, 'id')), array('id' => 'role_user_id_'.$user->id)) ?>
    <?= label_tag('role_user_id_'.$user->id, $user->login, array('for' => 'role_user_id_'.$user->id)) ?><br />
  </div>
  <? endforeach; ?>
  <?= $f->error_message_for('user_ids') ?>
</div>
<div class="field">
  <?= $f->label('permissions') ?><br />
  <?= hidden_field_tag('role[permission_ids][]', '') ?>
  <? foreach(Permission::find('all') as $permission) : ?>
  <div>
    <?= check_box_tag('role[permission_ids][]', $permission->id, in_array($permission->id, Permission::collection_to_array($role->permissions, 'id')), array('id' => 'role_permission_id_'.$permission->id)) ?>
    <?= label_tag('role_permission_id_'.$permission->id, $permission->name, array('for' => 'role_permission_id_'.$permission->id)) ?><br />
  </div>
  <? endforeach; ?>
  <?= $f->error_message_for('permission_ids') ?>
</div>
<div class="actions">
  <?= $f->submit() ?>
</div>